<?php
ob_start();

//错误显示
ini_set('display_errors', 1);
error_reporting(E_ALL);

require_once('cls_page.php');
require_once('du_system.php');

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<title>duphp_demo_2</title>
</head>
<body bgcolor="#cccccc">
<div class="inputdiv" style="width:60%; margin-left:10%">
	<?php

	if (isset($_POST['@cmd_type'])){
		
		$_content  = "<?php \n ob_start(); \n";
		$_content .= $_POST['incfile']."\n";
		
		$_content .= '$test = new Page();'."\n";
		$_content .= '$test->_page = isset($_GET["p"])?$_GET["p"]:1;'."\n";
		$_content .= '$test->_pageUrl 	= "";'."\n";
		$_content .= '$test->_tableName 	= "'.$_POST['tablename'].'";'."\n";
		$_content .= '$test->SetSelectSql("'. $_POST['selectsql'] . '");'."\n";
		$_content .= '$test->SetPageSize('. $_POST['pagesize'] .');'."\n";
		$_content .= '$test->SetItem("'. $_POST['setitem'] . '");'."\n";
		$_content .= '$test->SetItemField("'. $_POST['setitemfiled'] . '");'."\n";
		$_content .= '$test->SetItemLink("'. $_POST['SetItemLink'] . '");'."\n";
		$_content .= '$test->SetItemStyle("'. $_POST['SetItemStyle'] . '");'."\n";
		$_content .= '$test->SetControlStr("'. $_POST['SetControlStr'] . '");'."\n";
		$_content .= '$test->SetItemType("'. $_POST['SetItemType'] . '");'."\n";
		$_content .= '$test->SetItemModify("'. $_POST['SetItemModify'] . '");'."\n";
		$_content .= '$test->SetModifyUrl("'. $_POST['SetModifyUrl'] . '");'."\n";
		$_content .= 'if($_GET["act"]=="modify") {$test->DoModify();}'."\n";
		$_content .= 'if($_GET["act"]=="del") {$test->DoDel();}'."\n";
		$_content .= " ?> \n";
			
	 	$_content .= getHeadHtml($_POST['charset'],$_POST['title'],$_POST['cssorjs']);
		$_content .= sprintf($_POST['bodyhtml'],'<?php $test->ShowListAdmin(); ?>');		
		$_content .= "\n</html> \n";
		$filename = $_POST['filepath'];
		$handle = fopen ($filename,"w"); //打开文件指针，创建文件		
	 	if (!is_writable ($filename)){
			die ("文件：".$filename."不可写，请检查其属性后重试！");
	 	}
		if (!fwrite ($handle,$_content)){ //将信息写入文件
			die ("生成文件".$filename."失败！");
		} 
		fclose ($handle); //关闭指针 
		die ("创建文件".$filename."成功！<a href='".$filename."'>查看</a>");
			
	}
	
	echo html_input('form','','','','','','','','','','','','post','demo_2.php','');
	echo html_input('text','filepath','filepath','test.php','生成路径','textinput','','','','','','','','','');	
	echo html_input('text','charset','charset','utf-8','页面编码','textinput','','','','','','','','','');
	echo html_input('text','title','title','生成页面例子','页面标题','textinput','','','','','','','','','');	
	echo html_input('textarea','cssorjs','cssorjs','<link rel="stylesheet" type="text/css" href="style.css" media="screen" />','链CSS或JS','textareainput','','','','','','','','','');	
	echo html_input('textarea','incfile','incfile','require_once("cls_page.php");require_once("du_system.php");','包含文件','textareainput','','','','','','','','','');
	echo html_input('text','tablename','tablename','articles','数据表名','textinput','','','','','','','','','');
	echo html_input('text','pagesize','pagesize','5','分页大小','textinput','','','','','','','','','');
	echo html_input('text','selectsql','selectsql','SELECT date, title, text,id FROM articles ORDER BY id','SQL','textinput','','','','','','','','','');
	echo html_input('text','setitem','setitem','时间!$!标题!$!内容','SetItem','textinput','','','','','','','','','');	
	echo html_input('text','setitemfiled','setitemfiled','date!$!title!$!text','SetItemFiled','textinput','','','','','','','','','');
	echo html_input('text','SetItemLink','SetItemLink','!$!/#id#!$!','SetItemLink','textinput','','','','','','','','','');
	echo html_input('textarea','SetItemStyle','SetItemStyle',"style='text-align:center;width:20%'!$!style='text-align:center;width:30%'!$!style='color:red;text-align:center;width:30%'",'SetItemStyle','textareainput','','','','','','','','','');
	echo html_input('textarea','SetControlStr','SetControlStr',"<a href='index.php?id=#id#' #onclick#>修改</a> <a href='index.php?act=del&id=#id#'>删除</a>",'SetControlStr','textareainput','','','','','','','','','');
	echo html_input('text','SetItemType','SetItemType','1101!$!1101!$!1101','SetItemType','textinput','','','','','','','','','');
	echo html_input('text','SetItemModify','SetItemModify','n!$!y!$!y','SetItemModify','textinput','','','','','','','','','');
	echo html_input('text','SetModifyUrl','SetModifyUrl','index.php?act=modify','SetModifyUrl','textinput','','','','','','','','','');
	echo html_input('textarea','bodyhtml','bodyhtml',"<body>\n<div id='listmain'>\n<div class='list'>%s</div>\n</div>\n</body>",'页面内容[%s 来替换列表]','textareainput','','','','','','','','','');
	echo html_input('hidden', '@cmd_type', '@cmd_type', 'make','', '', '', '', '', '', '', '', '', '', '');
	echo html_input('submit', '', '', l('submit'),'','botton','','','','','','','','','');
	echo html_input('reset', '', '', l('reset'),'','botton','','','','','','','','','');			
	echo html_input('form','','','','','','','','','','','','end','','');
	?>
</div>
</body>
</html>


